// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-6-24

#include "stdafx.h"
#include "htmlview.h"
#include ".\htmlview.h"

// class CJoyHtmlView

IMPLEMENT_DYNCREATE(CJoyHtmlView, CHtmlView)

//##ModelId=44C4B6050189
CJoyHtmlView::CJoyHtmlView(void)
{
    m_showScroll = false;
}

//##ModelId=44C4B605018B
CJoyHtmlView::~CJoyHtmlView(void)
{
}

//##ModelId=44C4B6050197
void CJoyHtmlView::ShowScroll(bool show)
{
    m_showScroll = show;
}

//##ModelId=44C4B6050186
void CJoyHtmlView::ValidateBrowserSize(int cx, int cy)
{
    if(::IsWindow(m_wndBrowser.m_hWnd))
    {
        int dx = GetSystemMetrics(SM_CXEDGE);
        int dy = GetSystemMetrics(SM_CYEDGE);
        if(m_showScroll)
        {
            m_wndBrowser.MoveWindow(
                -dx, -dy,
                cx + 2*dx,
                cy + 2*dy);
        } 
        else
        {
            m_wndBrowser.MoveWindow(
                -dx, -dy,
                cx + GetSystemMetrics(SM_CXVSCROLL) + 2*dx,
                cy + GetSystemMetrics(SM_CYHSCROLL) + 2*dy);
        }
    }
}


BEGIN_MESSAGE_MAP(CJoyHtmlView, CHtmlView)
    ON_WM_SIZE()
    ON_WM_ERASEBKGND()
END_MESSAGE_MAP()


//##ModelId=44C4B6050199
void CJoyHtmlView::OnSize(UINT nType, int cx, int cy)
{
    //__super::OnSize(nType, cx, cy);
    CFormView::OnSize(nType, cx, cy);

    ValidateBrowserSize(cx, cy);
}

//##ModelId=44C4B605019E
BOOL CJoyHtmlView::OnEraseBkgnd(CDC* pDC)
{
    //Graphics graph(*pDC);
    //graph.Clear(Color(0xFF000000));
    //return TRUE;
    return CHtmlView::OnEraseBkgnd(pDC);
}

// class CJoyHtmlPanel

IMPLEMENT_DYNAMIC(CJoyHtmlPanel, CJoyWndContainer)

//##ModelId=44C4B60501BB
CJoyHtmlPanel::CJoyHtmlPanel(void)
{
    m_htmlView = NULL;
}

//##ModelId=44C4B60501BD
CJoyHtmlPanel::~CJoyHtmlPanel(void)
{
}

//##ModelId=44C4B60501C6
bool CJoyHtmlPanel::Create(CJoyWnd* parent, const CRect& area)
{
    if(!CreateEx(0,
        JoyGetManager()->GetWndClass(),
        NULL,
        WS_CHILD | WS_VISIBLE,
        area, parent,
        0))
    {
        return false;
    }
    //if(!__super::Create(parent, area))
    //{
    //    return false;
    //}
    m_htmlView = new CJoyHtmlView();
    if(!m_htmlView->Create(NULL, NULL, WS_VISIBLE | WS_CHILD, area, this, 0, NULL))
    {
        return false;
    }

    SetWnd(m_htmlView);
    //m_htmlView->ShowWindow(SW_HIDE);

    return true;
}

BEGIN_MESSAGE_MAP(CJoyHtmlPanel, CJoyWndContainer)
    ON_WM_CREATE()
    ON_WM_DESTROY()
END_MESSAGE_MAP()

//##ModelId=44C4B60501CB
int CJoyHtmlPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CJoyWndContainer::OnCreate(lpCreateStruct) == -1)
        return -1;

    return 0;
}

//##ModelId=44C4B60501D5
void CJoyHtmlPanel::OnDestroy()
{
    CJoyWndContainer::OnDestroy();

    if(m_htmlView != NULL)
    {
        m_htmlView->DestroyWindow();
        m_htmlView = NULL;
    }
}
